﻿#ifndef COMMONFUNC_H
#define COMMONFUNC_H

#include <QJsonObject>
#include <QString>
#include <functional>

enum XOperate
{
    XUI_Login = 0,
    XUI_Logout,
    XOverview,
    XUI_AreaManage,
    XUI_GateWayManage,
    XUI_DeviceManage,
    XUI_AbnormalManage,
    XUI_ShowThreshold,
    XUI_ShowStatus,
    XUI_ShowSpeed,

    XProductLine = 20,
    XShowGateWay,
    XShowDevice,
    XShowAbnormal,
    XShowSpeed,

    // http回执提示
    XLogin_Result = 100,
    XSetThreshold_Result
};

class QObject;

void createNetworkAccessManager(QObject *parent);

void updateAllMessageInfo();

void sendLoginInfo(const QString& strName, const QString &password);
bool readPersonID(const QJsonObject& json);

void sendProductLine();
bool readProductLineInfo(const QJsonObject& json);

void sendGateWayInfo();
bool readGateWayInfo(const QJsonObject& json);

void sendGetThresholdInfo();
bool readThresholdInfo(const QJsonObject& json);

void sendSensorDeviceRequest();
bool readSensorDeviceInfo(const QJsonObject& json);

void sendSensorStatusInfo();
bool readSensorStatusInfo(const QJsonObject& json);

void sendChangeThresholdValue(int value);

void appendTypeToFunc(int type, std::function<void()> func);
void removeTypeToFunc(int type);
std::function<void()> getFuncFromID(int type);
void executeFuncFromID(int id);

bool checkPersonID();
bool checkProductLineID();
bool checkGateWayID();

#endif // COMMONFUNC_H
